import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login.vue'
import Home from '@/views/Home.vue'
import UserList from '@/views/user/UserList.vue'
import RoleList from '@/views/role/RoleList.vue'
import Menus from '@/views/menu/Menus.vue'
import materialList from '@/views/dc/material/materialList.vue'
import MaterialAdd from "@/views/dc/material/MaterialAdd.vue";
import MaterialDes from '@/views/dc/material/MaterialDes.vue'
import Customer from "@/views/customer/Customer.vue";
import LinkMan from "@/views/dc/LinkMan.vue";
import CustomerAdd from "@/views/customer/CustomerAdd.vue";
import CustomerUpdate from "@/views/customer/CustomerUpdate.vue";
import link from "@/views/customer/link.vue";
import LinkAdd from '@/views/dc/LinkAdd'
import LinkUpdate from '@/views/dc/LinkUpdate'
import MaterialUpdate from "@/views/dc/material/MaterialUpdate"
import ProcessList from '@/views/dc/process/prolist'
import ProcessAdd from '../views/dc/process/proAdd'
import ProcessDes from '../views/dc/process/proDes'
import ProcessUpdate from '../views/dc/process/proUpdate'
import Order from '@/views/order/orderList'
import OrderAdd from '@/views/order/orderAdd'
import Make from '@/views/make/make'
import OrderUpdate from '@/views/order/orderUpdate'
import MakeAdd from '@/views/make/makeAdd'

import Clogin from "@/views/Clogin";

import CustomerHome from '@/views/CustomerHome'
import CustomerOrder from '@/views/cusaborder/CustomerOrder'
import IsOrder from '@/views/cusaborder/IsOrder'
import OkOrder from '@/views/cusaborder/OkOrder'
import  billAdd from '@/views/bill/billAdd.vue'
import Bil from "@/views/bil/bilList";
import  billList from "@/views/bill/billList";
import ALiPay from '@/views/ali/ALiPay'
import onelist from '@/views/one/index'
import  BillAdd from '@/views/bil/bilAdd'

Vue.use(VueRouter)

const routes = [
  {path:'/',redirect:'/login'},
  {name:'客户登录',path:'/clogin',component:Clogin},
  {path:'/customerHome',name:'客户端登录界面',component:CustomerHome,children:[
      {name:'客户订单',path:'/myorder',component:CustomerOrder},
      {name:'已付款订单',path:'/isorder',component:IsOrder},
      {name:'已转合同订单',path:'/okorder',component:OkOrder},
      {name:'发票管理',path:'/billAdd',component:billAdd},
      {name:'发票列表',path:'/billList',component:billList},
      {name:'回调支付',path:'/alipay',component:ALiPay}
    ]},

  {name:'登录',path:'/login',component:Login},
  {name:'主页',path:'/home',component:Home,children:[
      {name:'首页',path:'/toOneList',component:onelist},

      {name:'用户管理',path:'/userList',component:UserList},
      {name:'角色管理',path:'/roleList',component:RoleList},
      {name:'菜单管理',path:'/menus',component:Menus},

      {name:'客户管理',path:'/Customer',component:Customer},
      {name:'客户联系人查看',path:'/link',component:link},
      {name:'客户添加',path:'/CustomerAdd',component:CustomerAdd},
      {name:'客户编辑',path:'/CustomerUpdate',component:CustomerUpdate},

      {name:'联系人管理',path:'/linkMan',component:LinkMan},
	    {name:'联系人添加',path:'/linkAdd',component:LinkAdd},
      {name:'联系人修改',path:'/linkUpdate',component:LinkUpdate},

      {name:'原材料管理',path:'/material',component:materialList},
      {name:'原材料添加',path:'/materialAdd',component:MaterialAdd},
      {name:'原材料详情',path:'/materialDes',component:MaterialDes},
      {name:'原材料修改',path:'/materialUpdate',component:MaterialUpdate},

      {name:'工序管理',path:'/process',component:ProcessList},
      {name:'工序添加',path:'/processAdd',component:ProcessAdd},
      {name:'工序详情',path:'/processDes',component:ProcessDes},
      {name:'工序修改',path:'/processUpdate',component:ProcessUpdate},

      {name:'订单管理',path:'/order',component:Order},
      {name:'订单添加',path:'/orderAdd',component:OrderAdd},
      {name:'订单修改',path:'/orderUpdate',component:OrderUpdate},

      {name:'工艺管理',path:'/make',component:Make},
      {name:'工艺添加',path:'/makeAdd',component:MakeAdd},

      {name:'发票管理',path:'/bill',component:Bil},
      {name:'发票审核',path:'/bilAdd',component:BillAdd},
    ]
  },

]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {//to 路由目标 //from  //next 拦截补拦截，拦截到哪 路由守卫

  if(to.path=='/login' || to.path=='/clogin' || to.path=='/customerHome' || to.path=='/myorder' || to.path=='/isorder' ||to.path=='/okorder' ||to.path=='/toOneList'){ //当访问登录组件不拦截
    return next();
  }

  let linkman=sessionStorage.getItem("linkman");
  let user=sessionStorage.getItem("user");//获取sessionStorage中用户的信息
  let costomer=sessionStorage.getItem("costomer");//获取sessionStorage客户的信息
  if(user){
    //当前用户已登录
    return next();//继续访问
  }
  if(costomer){
    //当前用户已登录
    return next();//继续访问
  }
  if(linkman){
    //当前用户已登录
    return next();//继续访问
  }

  return  next('/login');
})


export default router
